//判段字典是否为
function isEmptyObject(obj) {
	if (JSON.stringify(obj) == '{}') {
		return true;
	} else {
		return false;
	}
};

function test(){
    document.getElementById('test').style.color='grey';
}

function test1(){
    document.getElementById('test').style.color='white';
}
//登录验证
function login(){
	var xmlhttp;//新建一个变量名
	var user = document.getElementById('exampleInputEmail1').value
	var pass_word = document.getElementById('exampleInputPassword1').value
	if (window.XMLHttpRequest)
	{
		//  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
		xmlhttp=new XMLHttpRequest();
	}
	else
	{
		// IE6, IE5 浏览器执行代码
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
            // document.getElementById(ID).innerHTML=xmlhttp.responseText;
			// // return xmlhttp.responseText

			// alert(xmlhttp.responseText);
			var result = JSON.parse(xmlhttp.responseText) //相当于python的json.loads方法

			if (result.status == 1){
				location.href='/static/base.html?render=user&access_token=' + result.resultBody.access_token + '&user_id=' + result.resultBody.user_id
			} else {
				alert(result.errorMsg)
			}
		}
	}
	//这里是发起请求
	xmlhttp.open("POST", '/login' , true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.send('user=' + user + '&pass_word=' + pass_word);
}

//验证access_token是否有效
function verify_access_token() {
	var xmlhttp;//新建一个变量名

	if (window.XMLHttpRequest)
	{
		//  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
		xmlhttp=new XMLHttpRequest();
	}
	else
	{
		// IE6, IE5 浏览器执行代码
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			var result = JSON.parse(xmlhttp.responseText) //相当于python的json.loads方法

			if (result.status == 1){
				// alert("access_token有效");
			} else {
				// console.log(result);
				alert('未登录或者超时');
				location.href="./base.html?render=login";
			}
		}
	}
	//这里是发起请求
	var url = "/access_token_verify" + location.search
	// alert(url)
	xmlhttp.open("GET", url, true);
	// xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.send();
}

//传入一个location.search返回对应的obj字典
function url_params_parse_obj(url_params){

	var params = url_params.substring(1);

	var x = params.split("&");

	var access_token;
	var user_id;
	var render;

	for(var i=0; i<x.length; i++){

		var ii = x[i].split('=')

		if (ii[0] == 'access_token'){
			access_token = ii[1]
		}else if (ii[0] == 'user_id'){
			user_id = ii[1]
		}
		
	}

	return {'access_token': access_token, 'user_id': user_id}

}

//传入一个location.search返回对应的obj字典
function locationSearchToDict(arg) {
	var reg = arg.match(/(\w+)=(\w+){1,}/g);
	//或者
	//var rgs = new RegExp("(\\w+)=(\\w+){1,}","g");
	//var reg = arg.match(rgs);
	// console.log(reg);
	var rrr = {};
	for (var i = 0; i < reg.length; i++) {
		var result = reg[i].split("=");
		rrr[result[0]] = result[1];
	}
	return rrr;
}



//叫车
function postCall(){

	var go_time = document.getElementById('go_time').value
	var place_departure = document.getElementById('place_departure').value
	var destination = document.getElementById('destination').value
	var number_people = document.getElementById('number_people').value
	var phone = document.getElementById('phone').value
	var carpooling_HitL = document.getElementById('carpooling_HitL').value
	var direction = document.getElementById('direction').value

	// 链接参数中的值
	var params = url_params_parse_obj(location.search)
	var user_id = params.user_id
	var access_token = params.access_token

	url_data = "go_time=" 
			   + go_time 
			   + "&place_departure="
			   + place_departure 
			   + '&destination='
			   + destination
			   + "&number_people="
			   + number_people
			   + "&phone="
			   + phone
			   + "&carpooling_HitL="
			   + carpooling_HitL
			   + "&direction="
			   + direction
			   + "&user_id="
			   + user_id
			   + "&access_token="
			   + access_token

	// alert(url_data)
	// alert(go_time + place_departure + phone + access_token)

	var xmlhttp;//新建一个变量名

	if (window.XMLHttpRequest)
	{
		//  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
		xmlhttp=new XMLHttpRequest();
	}
	else
	{
		// IE6, IE5 浏览器执行代码
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			var result = JSON.parse(xmlhttp.responseText) //相当于python的json.loads方法

			if (result.status == 1){
				// alert("access_token有效");
				alert("提交成功，请等待。。");
				ToXcgl();
				
			} else {
				alert(result.errorMsg);
				// location.href="/static/login.html";
			}
		}
	}
	//这里是发起请求
	var url = "/callCar"
	// alert(url)
	xmlhttp.open("POST", url, true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.send(url_data);

}

// 改变方向
function changeDirection() {

	var direction = document.getElementById('direction');
	var start = document.getElementById('start');
	var end = document.getElementById('end');


	if (direction.value == 0){
		direction.value = 1;
		var start_ = start.innerHTML;
		var end_ = end.innerHTML;
		start.innerHTML = end_;
		end.innerHTML = start_
		// alert("现在的方向值为:" + direction.value)
	}else {
		direction.value = 0;
		var start_ = start.innerHTML;
		var end_ = end.innerHTML;
		start.innerHTML = end_;
		end.innerHTML = start_
		// alert("现在的方向值为:" + direction.value)
	}

}
//base_main下的改变方向
function changeDirection_(carpooling_Hitl) {

	var direction = document.getElementById('direction');
	var start = document.getElementById('start');
	var end = document.getElementById('end');

	
	if (direction.value == 0){
		direction.value = 1;
		var start_ = start.innerHTML;
		var end_ = end.innerHTML;
		start.innerHTML = end_;
		end.innerHTML = start_;
		jinja2Order(0,0,carpooling_Hitl,1);
		
		// alert("现在的方向值为:" + direction.value)
	}else {
		direction.value = 0;
		var start_ = start.innerHTML;
		var end_ = end.innerHTML;
		start.innerHTML = end_;
		end.innerHTML = start_;
		jinja2Order(0,0,carpooling_Hitl,0);
		// alert("现在的方向值为:" + direction.value)
		// alert(direction.value);
	}

}

function jcc(){

	var params_dict = url_params_parse_obj(location.search);
	var jcc_dom = document.getElementById('jcc');
	var url = '/static/user.html' 
			  + '?access_token=' 
			  + params_dict.access_token
			  + '&user_id='
			  + params_dict.user_id
			  + '&jcc=1';
	jcc_dom.href = url;

}

function pcc(){
	var params_dict = url_params_parse_obj(location.search);
	var pcc_dom = document.getElementById('pcc');
	var url = '/static/user.html' 
			  + '?access_token=' 
			  + params_dict.access_token
			  + '&user_id='
			  + params_dict.user_id
	pcc_dom.href = url;

}

//如果是叫车车页面替换相应dom对象
function jcc_change(){

	var now_url = location.search;

	if (now_url.indexOf('jcc=1') != -1){

		document.getElementById('jcc_').style.backgroundColor = 'rgb(239, 235, 247)';
		document.getElementById('nav_bar').innerHTML = '叫车车';
		document.getElementById('carpooling_HitL').value = 1;

	}else{
		document.getElementById('pcc_').style.backgroundColor = 'rgb(239, 235, 247)';
		document.getElementById('nav_bar').innerHTML = '拼车车';
		
	}

}





// 发送验证码

function send_sms(phone) {

	var xmlhttp;//新建一个变量名

	if (window.XMLHttpRequest){
		//  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
		xmlhttp=new XMLHttpRequest();
	}else{
		// IE6, IE5 浏览器执行代码
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
			var result = JSON.parse(xmlhttp.responseText) //相当于python的json.loads方法
			var params = locationSearchToDict(location.search);
			if (result.status == 1){
				location.href = "/static/base.html?render=phone_verify" 
								+ "&notify_phone=" + phone
								+ "&access_token="
								+ params.access_token
								+ "&user_id="
								+ params.user_id
			} else {
				alert(result.errorMsg);
				// location.href="/static/login.html";
			}
		}
	}
	//这里是发起请求
	var url = "/app_phone_notify"
	// alert(url)
	xmlhttp.open("POST", url, true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.send("phone=" + phone);
}

//提交验证码
function phone_verify(phone, verify_code) {

	var xmlhttp;//新建一个变量名

	if (window.XMLHttpRequest){
		//  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
		xmlhttp=new XMLHttpRequest();
	}else{
		// IE6, IE5 浏览器执行代码
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
			var result = JSON.parse(xmlhttp.responseText) //相当于python的json.loads方法

			var param = locationSearchToDict(location.search);
			var param_need_str = '&notify_phone=' 
								 + param.notify_phone 
								 + "&access_token="
								 + param.access_token
								 + "&user_id="
								 + param.user_id

			if (result.status == 1){
				alert("验证通过");
				location.href = "/static/base.html?render=set_password" + param_need_str;
			} else if(result.errorCode == 43){
				alert(result.errorMsg);
				location.href="/static/base.html?render=phone_notify" + param_need_str;
			}else {
				alert(result.errorMsg);
			}
		}
	}
	//这里是发起请求
	var url = "/app_phone_verify"
	// alert(url)
	xmlhttp.open("POST", url, true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.send("phone=" + phone + "&verify_code=" + verify_code);



}

//更改密码
function set_password(phone, one_password, two_password) {

	var xmlhttp;//新建一个变量名

	if (window.XMLHttpRequest){
		//  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
		xmlhttp=new XMLHttpRequest();
	}else{
		// IE6, IE5 浏览器执行代码
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
			var result = JSON.parse(xmlhttp.responseText) //相当于python的json.loads方法

			if (result.status == 1){
				alert("修改成功，请重新登录");
				location.href = "./base.html?render=login";
			}else {
				alert(result.errorMsg);
			}
		}
	}
	//这里是发起请求
	var url = "/app_set_password"
	// alert(url)
	xmlhttp.open("POST", url, true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.send("phone=" + phone + "&one_password=" + one_password + "&two_password=" + two_password);

}


//更改密码
function changePhone(user_id, access_token) {

	var xmlhttp;//新建一个变量名

	if (window.XMLHttpRequest){
		//  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
		xmlhttp=new XMLHttpRequest();
	}else{
		// IE6, IE5 浏览器执行代码
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
			var result = JSON.parse(xmlhttp.responseText) //相当于python的json.loads方法

			if (result.status == 1){
				// alert("验证通过");
				console.log(result)
				document.getElementById('phone').value = result.resultBody
			}else {
				alert(result.errorMsg);
			}
		}
	}
	//这里是发起请求
	var url = "/app_get_phone"
	// alert(url)
	xmlhttp.open("POST", url, true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.send("user_id=" + user_id + "&access_token=" + access_token);

}


//渲染历史页面函数 
function render_history(resultBody){

	var result_str="";

	for(var i=0; i<resultBody.length; i++){

		var now_info = resultBody[i];

		var str_info;

		str_info = "<tr>"
				   + "<td>"
				   + now_info.go_time
				   + "</td>"
				   + "<td>"
				   + now_info.place_departure
				   + "</td>"
				   + "<td>"
				   + now_info.destination
				   + "</td>"
				   + "<td>"
				   + now_info.regedate
				   + "</td>"
				   + "</tr>";

		// console.log(str_info);
		result_str = result_str + str_info

	}

	console.log(result_str)

	return result_str


}



//history接口请求
function getHistory(user_id, access_token) {

	var xmlhttp;//新建一个变量名

	if (window.XMLHttpRequest){
		//  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
		xmlhttp=new XMLHttpRequest();
	}else{
		// IE6, IE5 浏览器执行代码
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
			var result = JSON.parse(xmlhttp.responseText) //相当于python的json.loads方法

			if (result.status == 1){

				var result_str = render_history(result.resultBody);

				document.getElementById('tbody').innerHTML = result_str;

				
			}else {
				alert(result.errorMsg);
				location.href = '/static/base.html?render=login';
			}
		}
	}
	//这里是发起请求
	var url = "/app_history"
	// alert(url)
	xmlhttp.open("POST", url, true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.send("user_id=" + user_id + "&access_token=" + access_token);

}

//验证当前页面是否有access_token参数和user_id参数
function verifyWebAccessToken() {
	var params = locationSearchToDict(location.search);

	if (params.access_token == undefined || params.user_id == undefined){
		alert(params.access_token);
		location.href = './base.html?render=login'
	}
}

function ToJcc(){

	var params = locationSearchToDict(location.search);

	var url = './base.html?render=user' 
			  + '&access_token=' 
			  + params.access_token
			  + '&user_id='
			  + params.user_id
			  + '&jcc=1';

	// document.getElementById()
	location.href = url;

}


function ToPcc(){

	var params = locationSearchToDict(location.search);

	var url = './base.html?render=user' 
			  + '&access_token=' 
			  + params.access_token
			  + '&user_id='
			  + params.user_id

	// document.getElementById()
	location.href = url;

}


function ToXcgl(){
	var params = locationSearchToDict(location.search);

	var xmlhttp;//新建一个变量名

	if (window.XMLHttpRequest){
		//  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
		xmlhttp=new XMLHttpRequest();
	}else{
		// IE6, IE5 浏览器执行代码
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
			var result = JSON.parse(xmlhttp.responseText).resultBody //相当于python的json.loads方法
			
			console.log(result);
			if(result.last_order_id == null){
				alert('你未登录/你还未叫过车');
			} else (

				location.href = "./base.html?render=order_detail_user"
								+ "&orderID="
								+ result.last_order_id
								+ "&user_id=" 
								+ params.user_id 
								+ "&access_token=" 
								+ params.access_token
			)
			
			
		}
	}
	//这里是发起请求
	var url = "/app_last_order_id?user_id=" + params.user_id;
	xmlhttp.open("GET", url, true);
	// xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.send();

}




function SL() {

	var SL_obj = document.getElementById('SL');

	// SL_obj.hidden = "hidden";

	if (SL_obj.hidden == true){

		SL_obj.hidden = false;

	}else{
		SL_obj.hidden = true;
	}

}

//出行记录的链接

function cxjl() {
	var cxjl_obj = document.getElementById("cxjl");
	var params = locationSearchToDict(location.search);
	cxjl_obj.href = "./base.html?render=history"
					+ "&access_token="
					+ params.access_token
					+ "&user_id="
					+ params.user_id;

}
//base页面·修改密码·的链接
function xgmm(){

	var cxjl_obj = document.getElementById("xgmm");
	var params = locationSearchToDict(location.search);
	cxjl_obj.href = "./base.html?render=phone_notify"
					+ "&access_token="
					+ params.access_token
					+ "&user_id="
					+ params.user_id;

}

//手机验证码，验证
function now_phone_verify() {

	var verify_code = document.getElementById("verify_code").value
	var phone = document.getElementById("verify_phone").value

	phone_verify(phone, verify_code)


}


function jiontOrder(resultBody) {

	var str_info = "";
	var str_order_status;

	for(var i=0; i < resultBody.length; i++){
		var now_info = resultBody[i];

		if(now_info['order_status'] == '未处理'){
			str_order_status = "<td>" 
								+ "<a class='red' href='./base_main.html?render=order_detail&orderID="
								+ now_info.id
								+ "'>"
								+ now_info.order_status
								+ "</a>"
								+ "</td>"
		}else {

			str_order_status =  "<td>" 
								+ "<a href='./base_main.html?render=order_detail&orderID="
								+ now_info.id
								+ "'>"
								+ now_info.order_status
								+ "</a>"
								+ "</td>"

		}

		var now_str = "<tr>"
					  + "<td>"
					  + now_info.id
					  + "</td>"
					  + "<td>"
					  + now_info.regedate
					  + "</td>"
					  + "<td>"
					  + now_info.go_time
					  + "</td>"
					  + str_order_status;

		str_info = str_info + now_str;
		// console.log(str_info);
	};

	return str_info;



}



//定单页面渲染,是管理员系统的方法
function jinja2Order(user_id, access_token, carpooling_Hitl, direction) {

	var xmlhttp;//新建一个变量名

	if (window.XMLHttpRequest){
		//  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
		xmlhttp=new XMLHttpRequest();
	}else{
		// IE6, IE5 浏览器执行代码
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
			var result = JSON.parse(xmlhttp.responseText);//相当于python的json.loads方法
			// console.log (xmlhttp.responseText);
			// console.log(jiontOrder(result.resultBody));
			document.getElementById("tbody").innerHTML = jiontOrder(result.resultBody);

			
		}
	}
	//这里是发起请求
	var url = "/app_order"
	// alert(url)
	xmlhttp.open("POST", url, true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.send(
		"user_id=" 
		+ user_id 
		+ "&access_token=" 
		+ access_token
		+ "&direction="
		+ direction
		+ "&carpooling_Hitl="
		+ carpooling_Hitl

		);

}


function orderDetail(orderID) {

	var xmlhttp;//新建一个变量名

	if (window.XMLHttpRequest){
		//  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
		xmlhttp=new XMLHttpRequest();
	}else{
		// IE6, IE5 浏览器执行代码
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
			var result = JSON.parse(xmlhttp.responseText);//相当于python的json.loads方法
			console.log(result);
			var result_order = result.resultBody.order;
			var result_order_status = result.resultBody.order_status;

			var render_str = '<tr>'
							+ '<th scope="row">下单时间</th>'
							+ '<td>' 
							+ result_order.regedate
							+'</td>'
							+ '</tr>'
							+ '<tr>'
							+ '<th scope="row">出发时间</th>'
							+ '<td>' 
							+ result_order.go_time
							+'</td>'
							+ '</tr>'
							+ '<tr>'
							+ '<th scope="row">包车/拼车</th>'
							+ '<td>' 
							+ result_order.carpooling_HitL
							+'</td>'
							+ '</tr>'
							+ '<tr>'
							+ '<th scope="row">方向</th>'
							+ '<td>' 
							+ result_order.direction
							+'</td>'
							+ '</tr>'
							+ '<tr>'
							+ '<th scope="row">上车地点</th>'
							+ '<td>' 
							+ result_order.place_departure
							+'</td>'
							+ '</tr>'
							+ '<tr>'
							+ '<th scope="row">下车地点</th>'
							+ '<td>' 
							+ result_order.destination
							+'</td>'
							+ '</tr>'
							+ '<tr>'
							+ '<th scope="row">人数</th>'
							+ '<td>' 
							+ result_order.number_people
							+'</td>'
							+ '</tr>'
							+ '<tr>'
							+ '<th scope="row">联系电话</th>'
							+ '<td>' 
							+ result_order.phone
							+'</td>'
							+ '</tr>';
			//订单已经被处理过
			if(isEmptyObject(result.resultBody.dirver) == false){
				var render_dirver = '</tr>'
									+ '<tr>'
									+ '<th scope="row">接车司机</th>'
									+ '<td>' 
									+ result.resultBody.dirver.dirver_name
									+'</td>'
									+ '</tr>'
									+ '<tr>'
									+ '<th scope="row">司机电话</th>'
									+ '<td>' 
									+ result.resultBody.dirver.dirver_phone
									+'</td>'
									+ '</tr>'
									+ '<tr>'
									+ '<th scope="row">管理员留言</th>'
									+ '<td>' 
									+ result_order_status.admin_remarks
									+'</td>'
									+ '</tr>'
									+ '<tr>'
									+ '<th scope="row">用户留言</th>'
									+ '<td>' 
									+ result_order_status.user_remarks
									+'</td>'
									+ '</tr>'
				render_str = render_str + render_dirver
									
			};

		
			document.getElementById("order_content").innerHTML = render_str;
			document.getElementById("order_id").innerHTML = "订单编号：" + result_order.id;
			document.getElementById('order_status').innerHTML = result_order_status.order_status;
			
			// alert("当前订单状态：" + result_order_status.order_status);
			//订单用户取消
			if(result_order_status.order_status == '用户取消该定单'){

				document.getElementById('processForm').hidden = true;

			}
		}
	}
	//这里是发起请求
	var url = "/app_order_detail/" + orderID;
	// alert(url)
	xmlhttp.open("GET", url, true);
	// xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.send();

}


//order_detail.html 司机信息渲染
function jinja2OrderDetailDriver() {

	var xmlhttp;//新建一个变量名

	if (window.XMLHttpRequest){
		//  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
		xmlhttp=new XMLHttpRequest();
	}else{
		// IE6, IE5 浏览器执行代码
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
			var result = JSON.parse(xmlhttp.responseText);//相当于python的json.loads方法
			// console.log (xmlhttp.responseText);
			console.log(result.resultBody);
			

			var render_str = '';

			for(var i=0; i<result.resultBody.length; i++){

				var now_obj = result.resultBody[i];

				render_str = render_str + '<option value="'
										+  now_obj.id
										+ '">' 
										+ now_obj.dirver_name 
										+ '</option>';

			}

			document.getElementById("inputState").innerHTML = render_str;
			
		}
	}
	//这里是发起请求
	var url = "/app_dirver"
	// alert(url)
	xmlhttp.open("get", url, true);
	// xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.send();

}

//add_dirver.html页面司机渲染

function jinja2AddDirver() {

	var xmlhttp;//新建一个变量名

	if (window.XMLHttpRequest){
		//  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
		xmlhttp=new XMLHttpRequest();
	}else{
		// IE6, IE5 浏览器执行代码
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
			var result = JSON.parse(xmlhttp.responseText);//相当于python的json.loads方法
			// console.log (xmlhttp.responseText);
			console.log(result.resultBody);
			

			var render_str = '';

			for(var i=0; i<result.resultBody.length; i++){

				var now_obj = result.resultBody[i];

				render_str = render_str + '<tr>'
										+  '<th scope="row">'
										+ now_obj.id
										+ '</th>'
										+  '<td>'
										+ now_obj.dirver_name
										+ '</td>'
										+  '<td>'
										+ now_obj.dirver_phone
										+ '</td>'
										+ '</tr>'

			}

			document.getElementById("dirver_info").innerHTML = render_str;
			
		}
	}
	//这里是发起请求
	var url = "/app_dirver"
	// alert(url)
	xmlhttp.open("get", url, true);
	// xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.send();

}


//add_dirver.html 添加司机接口js
function addDirver() {

	var xmlhttp;//新建一个变量名

	if (window.XMLHttpRequest){
		//  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
		xmlhttp=new XMLHttpRequest();
	}else{
		// IE6, IE5 浏览器执行代码
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
			var result = JSON.parse(xmlhttp.responseText);//相当于python的json.loads方法
			// console.log (xmlhttp.responseText);
			if (result.status == 1){
				location.href = location.href;
				alert('司机已加入');
			} else {
				alert(result.errorMsg);
			}
	
		}
	}
	//这里是发起请求
	var url = "/app_add_dirver"
	var dirver_name = document.getElementById('dirver_name').value;
	var dirver_phone = document.getElementById('dirver_phone').value;

	xmlhttp.open("POST", url, true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.send("dirver_name=" + dirver_name + "&dirver_phone=" + dirver_phone);

}




function process_order() {

	var xmlhttp;//新建一个变量名

	if (window.XMLHttpRequest){
		//  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
		xmlhttp=new XMLHttpRequest();
	}else{
		// IE6, IE5 浏览器执行代码
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
			var result = JSON.parse(xmlhttp.responseText);//相当于python的json.loads方法
			// console.log (xmlhttp.responseText);
			location.href = location.href;
			
			
		}
	}
	//这里是发起请求
	var url = "/app_process_order";
	order_id = document.getElementById('order_id').innerHTML.replace('订单编号：', '');
	// alert(order_id);
	dirver_id = document.getElementById('inputState').value;
	order_status = get_order_status();
	admin_remarks = document.getElementById('textarea').value;

	xmlhttp.open("POST", url, true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.send(
		"order_id=" 
		+ order_id 
		+ "&dirver_id=" 
		+ dirver_id
		+ "&order_status="
		+ order_status
		+ "&admin_remarks="
		+ admin_remarks
		);

}


function process_order_user() {

	var xmlhttp;//新建一个变量名

	if (window.XMLHttpRequest){
		//  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
		xmlhttp=new XMLHttpRequest();
	}else{
		// IE6, IE5 浏览器执行代码
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
			var result = JSON.parse(xmlhttp.responseText);//相当于python的json.loads方法
			// console.log (xmlhttp.responseText);
			location.href = location.href;
			
			
		}
	}
	//这里是发起请求
	var url = "/app_process_order_user";
	var order_id = document.getElementById('order_id').innerHTML.replace('订单编号：', '');
	// alert(order_id);
	var order_status = get_order_status();
	var user_remarks = document.getElementById('textarea').value;

	alert("当前留言框：" + user_remarks)

	xmlhttp.open("POST", url, true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.send(
		"order_id=" 
		+ order_id 
		+ "&order_status="
		+ order_status
		+ "&user_remarks="
		+ user_remarks
		);

}


function get_order_status(){
	var x = document.getElementsByName('exampleRadios');

	for(var i=0; i< x.length; i++){
		if(x[i].checked == true){
			// alert("当前选择了" +x[i].value )
			return x[i].value;
		};
	}

}


function process_order_button(){

	var x = document.getElementById('textarea');
	alert(x.nodeValue);

}